<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/layer/layer.js"></script>
    <SCRIPT language=javascript src="../../static/layer/layer.js"></SCRIPT>
</head>
<style>
    .maskpsd {
        display: none;
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.1);
        z-index: 999;
    }

    .maskpsd .register {
        position: absolute;
        width: 40%;
        left: 30%;
        top: 25%;
        border: 1px solid #cccccc;
        border-radius: 8px;
        background-color: #fff;
    }

    .maskpsd .register ul {
        padding: 5px 20px 10px;
    }

    .maskpsd .register ul li {
        position: relative;
        padding: 5px 10px;
        border-bottom: 1px solid #ccc;
        min-height: 40px;
        line-height: 40px;
    }

    .maskpsd .register ul li h3 {
        display: inline-block;
        font-size: 18px;
        font-weight: bold;
        color: #666;
    }

    .maskpsd .register ul li .closeBtn1 {
        cursor: pointer;
        position: absolute;
        top: 0;
        right: 0;
    }

    .maskpsd .register ul li .regSpan {
        display: inline-block;
        width: 100px;
        text-align: left;
        margin-right: 10px;
    }

    .maskpsd .register ul li input[type=text] {
        width: 50%;
        height: 30px;
        line-height: 40px;
        border: 1px solid #dedcdc;
        border-radius: 5px;
        background-color: #F7F7F7;
        font-size: 16px;
        padding-left: 10px;
        box-sizing: border-box;
    }

    .regUser1 {
        width: 4rem;
        cursor: pointer;
    }

    .change_psd {
        display: inline-block;
        color: #fff;
        float: right;
        margin-right: 5%;
        line-height: 60px;
        font-size: 14px;
        cursor: pointer;
    }
</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}


<div id="box" class="fl clearfix">
    <div class="content" style="height: 100%">
        <h3 style="color:  #3D89CB">用户车牌列表</h3>
        <div style="float: left; margin-left: 4.5rem; margin-bottom: 0.5rem"><button class="change_psd" style="display:
        block; width: 4rem; height: 2rem; line-height: 2rem">添加车牌</button></div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th width="10%">用户ID</th>
                <th width="12%">用户名</th>
                <th width="10%">车牌号码</th>
                <th width="10%">添加时间</th>
                <th width="20%">操作</th>
            </tr>
            </thead>

            <tbody>
            {% if res %}
                {% for d in res %}

                    <tr>
                        <td>{{ d.uid }}</td>
                        <td>{{ d.wxNickName }}</td>
                        <td>{{ d.license_plate }}</td>
                        <td>{{ d.add_time }}</td>
                        <td><button class="red"><a href="#" onclick="delete_plate({{ d.id }})">删除</a></button></td>
                    </tr>
                {% endfor %}
            {% else %}
                <tr class="color2">
                    <td colspan=8 align="center">暂无数据</td>
                </tr>
            {% endif %}


            </tbody>
        </table>


    </div>
</div>
</div>
<div class="maskpsd maskpsd2">
    <div class="register">
        <ul class="regBox">
            <li>
                <h3>添加车牌</h3>
                <span class="xxx closeBtn1">关闭</span>
            </li>
            <li>
                <span class="regSpan">车牌号码</span>
                <input type="text" title="" class="create" id="plate">
            </li>
            <li>
                <button class="regUser1" id="tjcp">提交</button>
            </li>
        </ul>
    </div>
</div>
</body>
</html>
<script>
    $('.change_psd').click(function () {
        $('.maskpsd2').show();
    });
    $('.closeBtn1').click(function () {
        $('.maskpsd2').hide();
    })
    function delete_plate(pid){
        layer.open({
            content: '你确定删除',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/delete_plate_post',
                    type: 'post',
                    data: {
                        'uid': {{ uid }},
                        'pid':pid
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
    $('#tjcp').click(function () {
        var plate = $('#plate').val();
        if (plate == ''){
            layer.msg("车牌号不能为空");
            return false;
        }
        $.ajax({
            url: '/admin/add_user_plate',
            type: 'post',
            data: {
                plate: plate,
                uid: {{ uid }}
            },
            success: function (msg) {
                if(msg.status == 1){
                    layer.msg("添加成功",{time:1600},function(){
                        location.reload();
                    })
                }else if(msg.status == 2){
                    layer.msg("用户不存在")
                }else if(msg.status == 3){
                    layer.msg("用户最多绑定3辆车");
                }else if(msg.status == 4){
                    layer.msg("车牌已被绑定");
                }else {
                    layer.msg("操作失败")
                }
            }
        })
    })
</script>


